<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html style="overflow: auto;">
<head>
    <title>入库单管理管理</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="decorator" content="ani"/>
    <%@ include file="/webpage/include/bootstraptable.jsp"%>
    <%@include file="/webpage/include/treeview.jsp" %>
    <style>
        html{
            width: 100vw;
        }
        .form_datetime{
            width: 100%;
        }
        .bootstrap-table .fixed-table-body{
            height: auto;
            overflow-y: hidden;
        }
    </style>

        <script type="text/javascript">

            $(document).ready(
                function(){
                var c = $(window.parent.document.body) 
                    c.find('.layui-layim-min').hide();
                }
            );
            $(window).unload(function(){
                console.log("Goodbye");
                var c = $(window.parent.document.body) 
                    c.find('.layui-layim-min').show();
            });


            $(function () {


                getbaseList();



            });


        function resca() {
            $("#state").val('');
            $("#evidenceId").val('');
            $("input[name='startDate']").val('');
            $("input[name='endDate']").val('');
            $("#warehouseName").val('');
            $("#receiptType").val('');
            $('#table').bootstrapTable('refresh', {
                query: {
                    pageSize: 15,
                    pageNumber: 1
                }
            })
        }


        function getbaseList() {

			var touchtime;
            $("#table").bootstrapTable({ // 对应table标签的id
                url: "${ctx}/warehouse/warehouseReceipt/data",
                contentType: "application/x-www-form-urlencoded",
                cache: false, // 设置为 false 禁用 AJAX 数据缓存， 默认为true
                striped: true,  //表格显示条纹，默认为false
                method: "POST",
                dataType: "json",
                pagination: true, // 在表格底部显示分页组件，默认false
                pageList: [10, 50, 100], // 设置页面可以显示的数据条数
                pageSize: 10, // 页面数据条数
                pageNumber: 1, // 首页页码
                sidePagination: 'server', // 设置为服务器端分页
                clickToSelect: true,
                paginationFirstText: "首页",
                paginationPreText: '上一页',
                paginationNextText: '下一页',
                paginationLastText: '最后一页',
                smartDisplay: false,
                queryParams : function(params) {
                    var searchParam = $("#searchForm").serializeJSON();
                    searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
                    searchParam.pageSize = params.limit === undefined? -1 : params.limit;
                    searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                    searchParam.evidenceId=$("#evidenceId").val();
                    searchParam.state=$("#state").val();
                    return searchParam;
                },
                onClickRow:function(row, $el, $event) {
                	   
            	    if (touchtime == 0) {
            	        // set first click
            	        touchtime = new Date().getTime();
            	    } else {
            	        // compare first click to this click and see if they occurred within double click threshold
            	        if (((new Date().getTime()) - touchtime) < 800) {
            	            touchtime = 0;
            	        /*     layer.open({
            	                type: 2,
            	                title: '入库单详情',
            	                maxmin: true,
            	                area: ['96%', '96%'],
            	                content: "${ctx}/warehouse/warehouseReceipt/view?evidenceId="+row.evidenceId
            	            }); */
            	            //改成非弹出层
            	            window.location.href = "${ctx}/warehouse/warehouseReceipt/view?evidenceId="+row.evidenceId;
            	        } else {
            	            // not a double click so set as a new first click
            	            touchtime = new Date().getTime();
            	        }
            	    }
            	},
                columns: [/* {
                    radio: true

                } *//* , {
                    // field: 'id',//可不加
                    title: '序号',//标题  可不加
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                } 
                    , */
                    {
                        field: 'purchaseNo',
                        title: 'ID',
                        sortable: true
                    }
	                , {
	                    field: 'poId',
	                    title: '采购单ID',
	                    sortable: true
	                }
	                , {
	                    field: 'purchaseDate',
	                    title: '采购日期',
	                    sortable: true
	                }
		                ,{
		                    field: 'state',
		                    title: '操作',
		                    sortable: true,
		                    formatter: function (value, row, index) {
	                            if(value=='1'){
	                           		return "<a href='${ctx}//warehouse/warehouseReceipt/createView?evidenceId="+row.evidenceId+"&purchaseOrderId="+row.poId+"'>质检入库</a>";
	                            }
	                            if(value=='0'){
	                                return "双击查看";
	                            }
	                        }
		                }
		                ,{
	                        field: 'state',
	                        title: '状态',
	                        sortable: true,
	                        formatter: function (value, row, index) {
	                            if(value=='1'){
	                               
	                                return "<font color='red'>质检</font>";
	                            }
	                            if(value=='0'){
	                                return "<font color='green'>完成</font>";
	                            }
	                        }
	                    }
               		 ,{
                        field: 'warehouseName',
                        title: '仓库',
                        sortable: true
                    },{
                        field: 'totalPlant',
                        title: '总量',
                        sortable: true
                    },{
                        field: 'confirmTotal',
                        title: '已入库量',
                        sortable: true
                    }
                    ,{
                        field: 'remarks',
                        title: '备注',
                        sortable: true

                    }
                    ,{
                        field: 'receiptType',
                        title: '凭证类型',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return jp.getDictLabel(${fns:toJson(fns:getDictList('sc_evidence_type'))}, value, "-");
                        }
                    }
                    ,{
                        field: 'updateDate',
                        title: '更新时间',
                        sortable: true
                    }
                    
                ],
                onLoadSuccess: function () {  //加载成功时执行
                    // console.info("加载成功");
                },
                onLoadError: function () {  //加载失败时执行
                    // console.info("加载数据失败");
                }

            })
        }

        //检索
        function subForm() {
            var evidenceId = $("#evidenceId").val();
            var state = $("#state").val();
            var startDate= $("input[name='startDate']").val();
            var endDate= $("input[name='endDate']").val();
            var warehouseName= $("#warehouseName").val();
            var receiptType=$("#receiptType").val();
            $('#table').bootstrapTable('refresh', {
                query: {
                    evidenceId:evidenceId,
                    state: state,
                    warehouseName:warehouseName,
                    startDate:startDate,
                    endDate:endDate,
                    receiptType:receiptType,
                    pageSize: 15,
                    pageNumber: 1
                }
            })

        }
/*已改成ajax请求 去除弹框
        function createPur(evidenceId,poId) {
            layer.open({
                type: 2,
                title: '采购入库创建',
                maxmin: true, //开启最大化最小化按钮*!/
                area: ['96%', '90%'],
                content: "${ctx}/warehouse/warehouseReceipt/createView?evidenceId="+evidenceId+"&purchaseOrderId="+poId
            });
        }
*/

        function createResourceRpit() {
            layer.open({
                type: 2,
                title: '创建入库单',
                maxmin: true, //开启最大化最小化按钮*!/
                area: ['96%', '90%'],
                offset: '10px',
                content: "${ctx}/warehouse/warehouseReceipt/addWarehouseReceipt"
            });
        }

        function loadExcel(evidenceId) {
            window.location.href="${ctx}/warehouse/warehouseReceipt/export?evidenceId="+evidenceId;
        }

        function openNew(evidenceId) {
            layer.open({
                type: 2,
                title: '扫码过机',
                maxmin: true,
                area: ['1400px', '500px'],
                content: "${ctx}/warehouse/warehouseReceipt/code?evidenceId="+evidenceId
            });
        }

        function view(evidenceId) {
            layer.open({
                type: 2,
                title: '入库单详情',
                maxmin: true,
                area: ['96%', '96%'],
                content: "${ctx}/warehouse/warehouseReceipt/view?evidenceId="+evidenceId
            });
        }
    </script>

<body style="width:100%; height:100%; overflow: scroll; -webkit-overflow-scrolling: touch;">
<div class="wrap">
<div class="panel-body" style="padding-bottom:0px; padding:0;">
    <div class="panel panel-default">
        <div cla  ss="panel-heading"> <h4>入库单</h4></div>
        <div class="panel-body">

            <div class="row" style="margin-left:5px; margin-top:10px;margin-right:15px;">


                <div class="form-group col-lg-2">
                    <div class="input-group">
                        <span class="input-group-addon">单号</span>
                        <input  name="evidenceId" id="evidenceId"
                                class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group col-lg-2">
                    <div class="input-group">
                        <span class="input-group-addon">状态</span>
                        <select  id="state" name="state" class="form-control">
                            <option value="">--请选择--</option>
                            <option value="1">质检</option>
                            <option value="0">完成</option>
                        </select>
                    </div>
                </div>
                <div class="form-group col-lg-2">
                    <div class="input-group">
                        <span class="input-group-addon">凭证类型</span>
                        <select  id="receiptType" name="receiptType" class="form-control">
                            
                        </select>
                    </div>
                </div>
                

            </div>
            <div class="row" style="margin-left:5px; margin-top:10px;margin-right:15px; ">
            	
                
                 <div class="form-group col-lg-2">
                        <div class="input-group">
                            <span class="input-group-addon">开始时间:</span>

                            <div class='input-group form_datetime' id='startDate'>
                                <input type='text' name="startDate"  class="form-control  required"
                                       value=""/>
                                <span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
                            </div>


                        </div>
                    </div>

                    <div class="form-group col-lg-2">
                        <div class="input-group">
                            <span class="input-group-addon">结束时间:</span>

                            <div class='input-group form_datetime' id='endDate'>
                                <input type='text' name="endDate" class="form-control  required"
                                       value=""/>
                                <span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
                            </div>


                        </div>
                    </div>
                    
                    <div class="form-group col-lg-2">
                  		<div class="input-group">
                        <span class="input-group-addon">仓库名称</span>
                        <input  name="warehouseName" id="warehouseName"
                                class="form-control" type="text">
                   		</div>
                	</div>
            </div>
            <script type="text/javascript">
            $('#startDate').datetimepicker({
                format: "YYYY-MM-DD"
            });
            $('#endDate').datetimepicker({
                format: "YYYY-MM-DD"
            });
            $.ajax({
                url:"${ctx}/warehouse/warehouseReceipt/findWarehouseReceiptType",
                type:"post",               
                success:function(data){
                	var optionstring = "<option value=''>"+"--请选择--"+"</option>";  
        	    	if(data!=null){
        		    	for(var i=0;i<data.length;i++){
        		    		 optionstring += "<option value=\"" + data[i].type+ "\">" +data[i].name+ "</option>";
        		    	}
        	    	}							    	
        	    	$("#receiptType").html(optionstring); 
                },
                
            });
            </script>

            <div class="row" style="margin-top:15px">
                <div class="col-sm-6"></div>
                <div class="col-sm-3" style="text-align:center;">
                    <button onclick="subForm()" type="button" style="margin-left:50px" id="btn_query"
                            class="btn btn-primary">查询
                    </button>
                    <button onclick="resca()" type="button" style="margin-left:50px" id="btn_query"
                            class="btn btn-large">重置
                    </button>
                </div>
                <div class="col-sm-3" style="text-align:center;">

                </div>
            </div>

        </div>
    </div>
</div>
<div id="toolbar" class="btn-group">
    <button id="btn_add" type="button" class="btn btn-default" onclick="createResourceRpit()" >
        <span class="glyphicon glyphicon-plus"></span>新增
    </button>
  <%--  <button id="btn_edit" onclick="updateProductAttribute()" type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-pencil"></span>修改
    </button>
    <button id="btn_delete" onclick="deleteProductAttribute()" type="button" class="btn btn-default">
        <span class="glyphicon glyphicon-remove"></span>删除
    </button>--%>
</div>

<!-- 列表list -->
<table id="table"></table></div>
</div>
</body>

</html>